﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Win32;
using VietApps.TouristManagement.AppCode;

namespace VietApps.TouristManagement
{
    public partial class frmCauHinhCSDL : Form
    {
        public AppDelegate.Login.EventLogin EventLogin;

        public frmCauHinhCSDL()
        {
            InitializeComponent();
        }
        void loadReg()
        {
            RegistryKey regLogin = Registry.CurrentUser.OpenSubKey(@"Software\TSC\RMS\Login");
            if (regLogin != null)
            {
                AppCfg.DBServerName = regLogin.GetValue("DBServerName").ToString();
                AppCfg.DBLoginName = regLogin.GetValue("DBLoginName").ToString();
                AppCfg.DBLoginPwd = regLogin.GetValue("DBLoginPwd").ToString();
                AppCfg.DBName = regLogin.GetValue("DBName").ToString();
            }
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                RegistryKey regLogin = Registry.CurrentUser.CreateSubKey(@"Software\TSC\RMS\Login");
                regLogin.SetValue("DBServerName", txtTenMayChu.Text);
                regLogin.SetValue("DBLoginName", txtTenDangNhap.Text);
                regLogin.SetValue("DBLoginPwd", txtMatKhau.Text);
                regLogin.SetValue("DBName", txtTenCSDL.Text);
                loadReg();
                MessageBox.Show(AppResources.MsgContent.saveSuccess, AppCode.AppResources.MsgTitle.infomation, MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, AppResources.MsgTitle.erro, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmDbCfg_Shown(object sender, EventArgs e)
        {
            try
            {
                RegistryKey regLogin = Registry.CurrentUser.OpenSubKey(@"Software\TSC\RMS\Login");
                if (regLogin != null)
                {
                    txtTenMayChu.Text = regLogin.GetValue("DBServerName").ToString();
                    txtTenDangNhap.Text = regLogin.GetValue("DBLoginName").ToString();
                    txtMatKhau.Text = regLogin.GetValue("DBLoginPwd").ToString();
                    txtTenCSDL.Text = regLogin.GetValue("DBName").ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, AppResources.MsgTitle.erro, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

    }
}
